/*
 * @Description: 字段名表头
 * @Author: Jevon
 * @Date: 2021-11-18 11:33:36
 */
import { h } from '../element';
import './style.css';
export default class Header {
  constructor(data) {
    this.el = h('div', 'vui-sheet-header').el;
    this.data = data;
  }

  render(viewRange, fw, fh, x, y) {
    const { el, data } = this;
    const { headerShow, headerData, headerCustom } = data.headerOption || {};
    this.clear();

    const item = document.createElement('div');
    item.className = 'vui-sheet-header-item';
    item.style.width = fw + 'px';
    el.appendChild(item);

    if (headerShow) {
      el.style.display = 'block';
    } else {
      el.style.display = 'none';
    }

    if (headerData) {
      data.colEach(viewRange.sci, viewRange.eci, (i, x1, colWidth) => {
        const col = headerData[i];
        const item = document.createElement('div');
        item.className = 'vui-sheet-header-item';
        item.style.width = colWidth + 'px';
        headerCustom(item, col, data);
        el.appendChild(item);
      });
    }
  }

  resetData(data) {
    this.data = data;
  }

  clear() {
    this.el.innerHTML = '';
  }
}
